package com.ash.insert;

import com.ash.util.ConnectionUtil;

import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Objects;

/**
 * @encoding : UTF-8
 * @Time : 2020/12/3 15:58
 * @Author : Chen Chao
 * @File : connection.com.ash.insert.Test01.java
 * @Software : IntelliJ IDEA
 * @since : 1.8
 * 插入语句
 */
public class Test01 {
    public static void main(String[] args) {
        Connection connection= ConnectionUtil.getConnection();
        Statement statement=null;
        try {
            /*3.创建sql语句*/
            String sql="insert into student values (121,'dog',18)";
            /*4.创建sql语句执行对象*/
            statement = Objects.requireNonNull(connection).createStatement();
            /*5.执行sql语句，DML返回受影响行数*/
            int i = statement.executeUpdate(sql);
            System.out.println(i);
        } catch ( SQLException e) {
            e.printStackTrace();
        } finally {
            ConnectionUtil.close(connection,statement,null);
        }


    }

}
